package com.hanvon.paycheck;
import java.io.File;

import android.R.integer;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import com.hanvon.signver.FileUtils;
import com.hanvon.signver.SignVer;
public class Main2Activity extends Activity implements OnClickListener {
    Button testBt;
    TextView resultTv;
    private short[] x= new short[]{0, 448, 463, 477, 492, 502, 506, 499, 486, 462, 436, 409, 385, 365, 349, 338, 338, 349, 376, 415, 471, 531, 603, 675, 745, -1}; // 笔迹数据数组
    private short[] y= new short[]{0, 139, 144, 158, 177, 205, 239, 274, 307, 334, 355, 366, 372, 371, 362, 349, 326, 301, 277, 264, 262, 269, 289, 312, 347, 0};// 笔迹数据数组
    private short[] p= new short[]{0, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 0}; // 笔迹数据数组
    private short[] t= new short[]{0, 40, 58, 76, 94, 112, 130, 147, 166, 183, 202, 220, 238, 257, 279, 293, 309, 327, 345, 363, 383, 402, 419, 438, 455, 0}; // 笔迹数据数组
    float a=0.01f;
    float b=0.02f;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        resultTv=(TextView)findViewById(R.id.result_tv);
        testBt=(Button)findViewById(R.id.test_bt);
        testBt.setOnClickListener(this);
    }
    public static float byte2float(byte[] b, int index) {
        int l;
        l = b[index + 0];
        l &= 0xff;
        l |= ((long) b[index + 1] << 8);
        l &= 0xffff;
        l |= ((long) b[index + 2] << 16);
        l &= 0xffffff;
        l |= ((long) b[index + 3] << 24);
        return Float.intBitsToFloat(l);
    }
    public void onClick(View view) {
        float div=0;
        div=a/b;
        Log.i("hello",""+div);
//        byte[] b=new byte[4];
//        b=SignVer.nativeSVGetSecurityLevel(b);
//        Log.i("hello", "xx="+Integer.toHexString((int)b[0]));
//        Log.i("hello", "xx="+Integer.toHexString((int)b[1]));
//        Log.i("hello", "xx="+Integer.toHexString((int)b[2]));
//        Log.i("hello", "xx="+Integer.toHexString((int)b[3]));
//        float f=byte2float(b,0);
 //       Log.i("hello","f="+f);
       File file=FileUtils.write2SDFromString("Signature/log/","log.txt","");
       Log.i("logfile=","logfile="+file.getAbsolutePath());
        boolean bl;
        for(int i=0;i<5;i++){
           bl = SignVer.nativeSVLearn(x.length, x, y, t, p);
        }
        int len = SignVer.nativeSVGetTemplLen();
        Log.i("hello", "templLen=" + len);
        byte[] temp = new byte[len];

        bl = SignVer.nativeSVGetTemplate(temp);
        Log.i("hello", "getTemp=" +bl );
        bl = SignVer.nativeSVCheckSig(temp,x.length, x, y, t, p);
        Log.i("hello", "check=" + bl);
        int re = SignVer.nativeSVGetSimilarScore();
        Log.i("hello", "SimilarScore=" + re);
        resultTv.setText("相似度：" + re + "%");
    }
}
